-
-
Notifications
You must be signed in to change notification settings - Fork 399
drivers/, dummy-ups: modernize status/alarm handling, ALARM instruction for dummy modes #2936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
drivers/, dummy-ups: modernize status/alarm handling, ALARM instruction for dummy modes #2936
Conversation
…RM instruction for dummy modes Signed-off-by: desertwitch <[email protected]>
Signed-off-by: desertwitch <[email protected]>
Signed-off-by: desertwitch <[email protected]>
…dling changes Signed-off-by: desertwitch <[email protected]>
Signed-off-by: desertwitch <[email protected]>
Signed-off-by: desertwitch <[email protected]>
Signed-off-by: desertwitch <[email protected]>
|
Had some more time and figured this would also fit into this PR (and save on CI cycles), fixes #2937. |
… outlets No longer evaluate outlet status in instant command handling, but rather in the main update cycle. Raising OFF for a turned-off outlet aligns with the behavior of the clone-outlet driver. Signed-off-by: desertwitch <[email protected]>
…ges [networkupstools#2936] Signed-off-by: desertwitch <[email protected]>
…etworkupstools#2936] Signed-off-by: desertwitch <[email protected]>
…ous work [networkupstools#2936] Signed-off-by: desertwitch <[email protected]>
jimklimov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable, but there's a lot of change in clone driver that I couldn't quite wrap my head around. Did you have some chance to test that it still works (no worse than before)? :)
| status_init(); | ||
|
|
||
| if (outlet.status == 0) { | ||
| upsdebugx(2, "OFF flag set (%s: switched off)", prefix.status); | ||
| dstate_setinfo("ups.status", "%s OFF", ups.status); | ||
| return; | ||
| status_set("OFF"); | ||
| } | ||
|
|
||
| if ((outlet.timer.shutdown > -1) && (outlet.timer.shutdown <= outlet.delay.shutdown)) { | ||
| upsdebugx(2, "FSD flag set (%s: -1 < [%ld] <= %ld)", prefix.timer.shutdown, outlet.timer.shutdown, outlet.delay.shutdown); | ||
| dstate_setinfo("ups.status", "FSD %s", ups.status); | ||
| return; | ||
| status_set("FSD"); | ||
| } | ||
|
|
||
| upsdebugx(3, "%s: power state not critical", getval("prefix")); | ||
| dstate_setinfo("ups.status", "%s", ups.status); | ||
| status_set(ups.status); /* FIXME: Split token words? */ | ||
| status_commit(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noting, with no judgement, that this also subtly changes the logic: previously the driver applied either "OFF" or "FSD" to existing ups.status and returned; now it can apply both.
It also no longer reports that the "power state is not critical" in debug log, though that may be not too useful as such.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intended because the user should see all actual statuses and OFF/FSD should not be mutually exclusive, I did drop the debug message - sorry - but I think it made no sense when a UPS may well be OB LB or OVER even if not OFF or FSD yet, which would also be somewhat critical.
I did also pave it over for ease of coding around it, other than the argument above, truth be told, since all statuses (also critical ones) are reported summarily now.
Yes, all thinkable scenarios were tested by me and the driver works as before. It may look like many changes but it's mostly moving things around to reduce redundant expensive checks via dstate to locations where we can also check it from the data we have. The same applies to setting statuses from deeply nested parsing functions, which was refactored into setting internal state instead and then updating from that in a central location in the update loop. I think the only behavioral change in As far Happy to answer any questions! |
| struct { | ||
| char *off; | ||
| char *on; | ||
| char *status; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stores the user set arguments for re-use, instead of getvaling them all over
|
|
||
| if (ups.load.status && !strcasecmp(arg[1], ups.load.status)) { | ||
| if (!strcasecmp(arg[2], "off") || !strcasecmp(arg[2], "no")) { | ||
| outlet = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sets internal state from data we have, for later updating from directly in upsdrv_updateinfo(), instead of then needing to dstate_getinfo it again otherwhere to the same effect.
| if (val) { | ||
| if (!strcasecmp(val, "off") || !strcasecmp(val, "no")) { | ||
| outlet = 0; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to parse_args where we have this information, if the outlet is off should not be set inside an instant command handling function, but where the data actually comes in and is parsed. This also obsoletes the need for the redundant dstate check which is expensive.
|
|
||
| ups.load.off = getval("load.off"); | ||
| ups.load.on = getval("load.on"); | ||
| ups.load.status = getval("load.status"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Record the user given arguments into the internal state struct, reduces needs for constant getvaling them within update loops.
| if (ups.load.status && !reported_off) { /* first entrance */ | ||
| reported_off = 1; | ||
| upslogx(LOG_WARNING, "%s: upstream reports outlet off (setting OFF)", | ||
| __func__); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inform user that the outlet is reported off and set OFF to make it consistent with clone-outlet, the user can see on a first glance the outlet is not giving power.
| } | ||
|
|
||
| if (!ups.load.status) { | ||
| /* Better than nothing if no load.status argument was given, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If no argument was given where to check the outlet's actual status, we assume it to have successfully turned off after sending ups.load.off for lack of a variable for checking. If an argument was given, no assumptions are made and the actual status of the outlet is checked.
Same as before, but it was just set here and overridden later in an unexpected place instcmd, this way should be cleaner and more traceable with debug messages.
|
|
||
| dstate_setinfo("ups.status", "%s", ups.status); | ||
| if (!ups.load.status) { | ||
| /* Better than nothing if no load.status argument was given, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above: assume it to be on when the command was sent, if no argument for checking the status was given. Follows behaviour as before, just more traceable.
|
Super, thanks for the analyses! |
follow up to #2934
fixes #2937
implements ideas of #2928, #2931
modernizes remaining 4 drivers to use the contemporary best-practice status/alarm handling:
introduces an
ALARMinstruction for dummy modes indummy-upsto allow simulating modern alarms: